package com.xplay.xpocker.service.gaming.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xplay.xpocker.entity.GameRuMahjongUser;
import com.xplay.xpocker.mapper.GameRuMahjongUserMapper;
import com.xplay.xpocker.service.gaming.GameRuMahjongUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xplay.xpocker.service.system.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author xplay
 * @since 2023-08-19
 */
@Service
public class GameRuMahjongUserServiceImpl extends ServiceImpl<GameRuMahjongUserMapper, GameRuMahjongUser> implements GameRuMahjongUserService {
    @Autowired
    private ISysUserService userService;

    @Override
    public GameRuMahjongUser queryUserInfo(BigDecimal userId) {
        LambdaQueryWrapper<GameRuMahjongUser> ruUserWrapper = Wrappers.lambdaQuery(GameRuMahjongUser.class).eq(GameRuMahjongUser::getUserId, userId);
        return getOne(ruUserWrapper);
    }

    @Override
    public GameRuMahjongUser createOrUpdate(GameRuMahjongUser mahjongUser) {
        GameRuMahjongUser userInfo = queryUserInfo(mahjongUser.getUserId());
        if (userInfo == null) {
            save(mahjongUser);
        } else {
            updateById(mahjongUser);
        }
        return mahjongUser;
    }
}
